﻿@using System.Collections
@model MMSWebsite.Models.Customer
<table >
      <tr>
        <td class="tdLeft" > @Html.LabelFor(model => model.Code)</td>
        <td class="tdRight"> @Html.EditorFor(model => model.Code)
            @Html.ValidationMessageFor(model => model.Code)</td>
    </tr>
    <tr>
        <td class="tdLeft"> @Html.LabelFor(model => model.Name)</td>
        <td class="tdRight"> @Html.EditorFor(model => model.Name)
            @Html.ValidationMessageFor(model => model.Name)</td>
    </tr>
    <tr>
        <td class="tdLeft"> @Html.LabelFor(model => model.IdCode)</td>
        <td class="tdRight"> @Html.EditorFor(model => model.IdCode)
            @Html.ValidationMessageFor(model => model.IdCode)</td>
    </tr>
    <tr>
        <td class="tdLeft"> @Html.LabelFor(model => model.Email)</td>
        <td class="tdRight"> @Html.EditorFor(model => model.Email)
            @Html.ValidationMessageFor(model => model.Email)</td>
    </tr>
    <tr>
        <td class="tdLeft"> @Html.LabelFor(model => model.Phone)</td>
        <td class="tdRight"> @Html.EditorFor(model => model.Phone)
            @Html.ValidationMessageFor(model => model.Phone)</td>
    </tr>
    <tr>
        <td class="tdLeft"> @Html.LabelFor(model => model.Sex)</td>
        <td class="tdRight"> @Html.EditorFor(model => model.Sex)
            @Html.ValidationMessageFor(model => model.Sex)</td>
    </tr>
    <tr>
        <td class="tdLeft"> @Html.LabelFor(model => model.Birth)</td>
        <td class="tdRight"> @Html.EditorFor(model => model.Birth)
            @Html.ValidationMessageFor(model => model.Birth)</td>
    </tr>
        <tr>
        <td class="tdLeft"> @Html.LabelFor(model => model.CompanyNm)</td>
        <td class="tdRight"> @Html.EditorFor(model => model.CompanyNm)
            @Html.ValidationMessageFor(model => model.CompanyNm)
        </td>
    </tr>
    <tr>
        <td class="tdLeft"> @Html.LabelFor(model => model.Tax)</td>
        <td class="tdRight"> @Html.EditorFor(model => model.Tax) 
            @Html.ValidationMessageFor(model => model.Tax)</td>
    </tr>
    <tr>
        <td class="tdLeft"> @Html.Label("Address")</td>
        <td class="tdRight">
            <table >
                <tr>
                    <td class="tdLeft">  Number Address</td>
                    <td class="tdRight"> @Html.EditorFor(model => model.NumberAddress) </td>
                </tr>
                <tr>
                    <td class="tdLeft">  City</td>
                    <td class="tdRight"> @Html.DropDownListFor(model => model.Area.CityName, new SelectList(ViewBag.Cities as IEnumerable), string.Empty)
                        @Html.ValidationMessageFor(model => model.Area.CityName) </td>
                </tr>
                <tr>
                    <td class="tdLeft">  District</td>
                    <td class="tdRight">  @Html.DropDownListFor(model => model.Area.DistrictName, new SelectList(ViewBag.Districts as IEnumerable), string.Empty)
                        @Html.ValidationMessageFor(model => model.Area.DistrictName) </td>
                </tr>
            </table>
        </td>
    </tr>
    <tr>
        <td  class = "tdRight" colspan="2" style="text-align: center">
            <input type="submit" value="Save"> 
        </td>
           
    </tr>
</table>

<script type="text/javascript">

    //Set Code Field Is Disable
    $(document).ready(function () {
        $('#@Html.IdFor(model=>model.Code)').attr("readonly", true);
    });

    //Cascading dropdownlist city and district
    var selector = {
        City: "select#@Html.IdFor(model => model.Area.CityName)",
        District: "select#@Html.IdFor(model => model.Area.DistrictName)"
    };

    $(selector.City).change(function () {
        selectFromAjax('@Url.Action("DistrictList", "Employee")', { city: $(this).find("option:selected").val() }, $(selector.District));
        console.log($(this).find("option:selected").val());
    });

</script>
